package cn.nexd.app.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import java.util.List;


import cn.nexd.app.arsenal.R;


/**
 * Created by xun on 2016/5/8.
 */
public class CityAdapter extends BaseAdapter {
    private Context context;
    private List<String> cities;
    private LayoutInflater layoutInflater;
    private int selectedPosition;
    private int num;
//    private SparseArray<Boolean> statusMap;


    public CityAdapter(Context context, List<String> cities) {
        this.context = context;
        this.cities = cities;
        this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return cities.size();
    }

    @Override
    public Object getItem(int position) {
        return cities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, final ViewGroup parent) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_city_list, parent, false);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvCity.setText(cities.get(position));
        if (selectedPosition == position) {
            viewHolder.tvCity.setTextColor(Color.parseColor("#44BF1A"));
            viewHolder.tvStatus.setBackgroundColor(Color.parseColor("#44bf1a"));
            convertView.setBackgroundColor(Color.TRANSPARENT);
        } else {
            viewHolder.tvCity.setTextColor(Color.parseColor("#000000"));
            viewHolder.tvStatus.setBackgroundColor(Color.TRANSPARENT);
            convertView.setBackgroundColor(Color.LTGRAY);
        }

        return convertView;
    }

    class ViewHolder {
        TextView tvStatus;
        TextView tvCity;

        public ViewHolder(View convertView) {
            tvStatus = (TextView) convertView.findViewById(R.id.item_tv_bg);
            tvCity = (TextView) convertView.findViewById(R.id.item_tv_city);
        }
    }

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }

    public void setMallNum(int num) {
        this.num = num;
    }


}
